package gjtx7;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Formats {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("输入一个日期:");
        String str = in.nextLine();
       SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
       // df.setLenient(false);
        try {
            Date d = df.parse(str);
            System.out.println(d+" "+"成功1");
            return;
        } catch (ParseException e) {

        }
        SimpleDateFormat df1= new SimpleDateFormat("yyyy-MM-dd");
        //df1.setLenient(false);
        try {
            Date d=df1.parse(str);
            System.out.println(d+"  "+"成功2");
            return;
        } catch (ParseException e) {

        }
        SimpleDateFormat  df2= new SimpleDateFormat("yyyyMMdd");
       df2.setLenient(false);
        try {
            Date d=df2.parse(str);
            System.out.println(d+" "+"成功3");
            return;
        } catch (ParseException e) {
            System.out.println("日期格式非法");
        }
    }
}
